module CamReader(
	iCLK,
	iPCLK,
	iData,
	iX,
	iY,
	iFrame,
	oResult
);

input iCLK;
input iPCLK;
input[7:0] iData;
input[9:0] iX, iY;
input iFrame;
output[7:0] oResult;

localparam WIDTH	= 640;
localparam HEIGHT = 480;

reg[9:0] width, center;

always@ (posedge iPCLK) begin
	if(iData > 8'd220) begin
		if(width == 10'd0) center <= iX;
		else if(width[0] == 1'b0) center <= center + 1'b1;
		width <= width + 1'b1;
		fifo_wr <= 1'b0;
	end
	else begin
		width <= 9'd0;	
		if(width > 9'd2)begin	
			fifo_in <= {center, iY, width};
			fifo_wr <= 1'b1;
		end
		else fifo_wr <= 1'b0;
	end
end

assign fifo_clk = ~iPCLK;

reg[29:0] fifo_in;
wire[29:0] fifo_out;
reg fifo_wr, fifo_rd, fifo_clr = 0;
wire fifo_clk;
FIFO fifo(
		.clock(fifo_clk),
		.data(fifo_in),
		.rdreq(fifo_rd),
		.sclr(fifo_clr),
		.wrreq(fifo_wr),
		.empty(),
		.full(),
		.q(),
		.usedw(oResult));

endmodule
